package com.ruoyi.system.utils;

import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * id生成工具
 */
public class IdentifiedGenerator {
    public static String generate(){
        return UUID.randomUUID().toString().replace("-", "");
    }

    //随机生成六位数，并且每位数都不重复
    public static int Num() {
        int[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        Random rand = new Random();
        for (int i = 10; i > 1; i--) {
            int index = rand.nextInt(i);
            int tmp = array[index];
            array[index] = array[i - 1];
            array[i - 1] = tmp;
        }
        int result = 0;
        for (int i = 0; i < 6; i++) {
            result = result * 10 + array[i];
        }
        if (String.valueOf(result).length() == 6) {
            return result;
        } else {
            return Num();
        }
    }

    public static void qu(List l){
        for  ( int  i  =   0 ; i  <  l.size()  -   1 ; i ++ )  {
            for  ( int  j  =  l.size()  -   1 ; j  >  i; j -- )  {
                if  (l.get(j).equals(l.get(i)))  {
                    l.remove(j);
                }
            }
        }
    }

}